package com.li.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.li.hibenate.HibernateSessionFactory;
import com.li.hibenate.pojo.Student;



public class StudentDao {
	
	public boolean save(Student stu){
		Session session = HibernateSessionFactory.getSession();
		Transaction t = session.beginTransaction();
		try {
			session.save(stu);
			t.commit();
			
		} catch (HibernateException e) {
			t.rollback();
			e.printStackTrace();
			return false;
		}
	
		return true;
	}
	public List<Student> login(String sname,String spwd){
		String hql = "from student where sname = ? and password = ? and state = ?";
		Session session = HibernateSessionFactory.getSession();
		Query query = session.createQuery(hql);
		List<Student>list = session.createQuery(hql).setString(0, sname).setString(1, spwd).list();
		return list;
	}

}
